<template>
  <div class="student">
    <Breadcrumb></Breadcrumb>
    <section>
      <el-form
        :inline="true"
        :model="formInline"
        ref="formInline"
        class="demo-form-inline"
      >
        <el-form-item label="学员状态">
          <el-select v-model="formInline.region" placeholder="请选择">
            <el-option label="禁用" value="0"></el-option>
            <el-option label="启用" value="1"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="学生名称">
          <el-input
            v-model="formInline.username"
            placeholder="请输入学生关键字"
          ></el-input>
        </el-form-item>
        <el-form-item label="手机号">
          <el-input
            v-model="formInline.phone"
            placeholder="请输入手机号"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button icon="el-icon-search" @click="getUsers()">搜索</el-button>
          <el-button icon="el-icon-refresh" @click="onReset('formInline')"
            >重置</el-button
          >
        </el-form-item>
      </el-form>
      <p>
        <el-button
          type="primary"
          size="medium"
          @click="$router.push('/index/User/student-edit')"
          >新增学员</el-button
        >
        <el-button type="primary" size="medium">批量导入</el-button>
        <el-button type="primary" size="medium">批量导出</el-button>
        <el-button type="primary" size="medium">查看报表</el-button>
      </p>
      <!-- 表格数据 -->
      <el-table
        border
        stripe
        ref="multipleTable"
        :data="tableData"
        tooltip-effect="dark"
        style="width: 100%"
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" width="55"> </el-table-column>
        <el-table-column label="学生姓名">
          <template slot-scope="scope"
            ><img :src="scope.row.avatar" alt="" />{{
              scope.row.nickname
            }}</template
          >
        </el-table-column>
        <el-table-column prop="mobile" label="手机号"> </el-table-column>
        <el-table-column label="状态">
          <template slot-scope="scope">
            <span v-show="scope.row.status == 1">启用</span
            ><span v-show="scope.row.status == 0">禁用</span>
          </template>
        </el-table-column>
        <el-table-column prop="created_at" label="创建时间"> </el-table-column>
        <el-table-column fixed="right" label="操作" min-width="100">
          <template slot-scope="scope">
            <el-button @click="handleClick(scope.row)" type="text" size="small"
              >详情</el-button
            >
            <el-button type="text" size="small">编辑</el-button>
            <el-button type="text" size="small">禁用</el-button>
            <el-button type="text" size="small">删除</el-button>
            <el-button type="text" size="small">重置密码</el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[10, 20, 30, 40]"
        :page-size="pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </section>
  </div>
</template>

<script>
import Breadcrumb from "../../components/Breadcrumb";
export default {
  name: "Student",
  components: { Breadcrumb },
  data() {
    return {
      formInline: {
        region: "",
        username: "",
        phone: ""
      },
      // 表格数据
      tableData: [],
      currentPage: 1,
      pagesize: 10,
      total: 0
    };
  },
  created() {},
  mounted() {
    this.getUsers();
  },
  methods: {
    // 获取表格数据
    async getUsers() {
      let { data: res } = await this.$axios.user({
        page: this.currentPage,
        limit: this.pagesize,
        status: this.formInline.region,
        nickname: this.formInline.username,
        mobile: this.formInline.phone
      });
      console.log(res);
      this.tableData = res.data.list;
      this.total = res.data.total;
    },
    // 重置按钮
    onReset() {
      this.formInline.region = "";
      this.formInline.username = "";
      this.formInline.phone = "";
      this.getUsers();
    },
    // 复选框
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.pagesize = val;
      this.getUsers();
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.currentPage = val;
      this.getUsers();
    },
    // 表格中详情按钮
    handleClick() {}
  }
};
</script>

<style lang="scss" scoped>
section {
  padding: 10px;
}
img {
  width: 30px;
  height: 30px;
  border-radius: 100%;
  vertical-align: middle;
  margin-right: 10px;
}
p {
  margin-bottom: 10px;
}
</style>
